var storage = window.localStorage;
// var bankId = GetQueryString('bankId');
// var appuuid = GetQueryString('appuuid');
// var authorization = GetQueryString('authorization');
// var arr = new Array();
// arr = authorization.split('_');//注split可以用字符或字符串分割





function showAgreement(){
	var showAgreementBox = document.getElementsByClassName("showAgreementBox")[0];
	showAgreementBox.style.display = "block";
}

function hideAgreement(){
	var showAgreementBox = document.getElementsByClassName("showAgreementBox")[0];
	showAgreementBox.style.display = "none";
}

function submitBox(){
	
	var own_name = document.getElementById("user_name").value;
	var own_identity = document.getElementById("user_identity").value;
	var own_phone = document.getElementById("tel").value;
	var vfycode = document.getElementById("vfyCodel").value;
	
	//首先校验表单内容
	if(own_name == ""){
		return prompt("请输入真实姓名");
	}else if(own_identity == ""){
		return prompt("请输入身份证号");
	}else if(own_phone==""||own_phone==null){
		return prompt("手机号码不能为空");
	}else if(!/^1[3|4|5|6|7|8|9]\d{9}$/.test(own_phone)){
		return prompt("请输入11位正确的手机号码");
	}else if(vfycode == ""){
		return prompt("请输入短信验证码");
	}
	
	var submitBox = document.getElementsByClassName("submitBox")[0];
	submitBox.style.display = "block";
	getValue();
}

//提交后取消
function choose_cancle(){
	var submitBox = document.getElementsByClassName("submitBox")[0];
	submitBox.style.display = "none";
}
// 确认提交
$(".choose_sure").click(function bb(){
	console.log(333);
	choose_cancle();
	
	// 解绑 click事件
	//$(".choose_sure").unbind('click');

    var param = document.getElementById("param").value;
    var csrf_token = document.getElementById("csrf_token").value;
    var own_name = document.getElementById("user_name").value;
	var own_identity = document.getElementById("user_identity").value;
	var own_phone = document.getElementById("tel").value;
	var vfycode = document.getElementById("vfyCodel").value;
	
	if(own_name == ""){
		//$(".choose_sure").bind('click', bb); // 恢复click事件
		return prompt("请输入真实姓名");
	}else if(own_identity == ""){
		//$(".choose_sure").bind('click', bb); // 恢复click事件
		return prompt("请输入身份证号");
	}else if(own_phone==""||own_phone==null){
		//$(".choose_sure").bind('click', bb); // 恢复click事件
		return prompt("手机号码不能为空");
	}else if(!/^1[3|4|5|6|7|8|9]\d{9}$/.test(own_phone)){
		//$(".choose_sure").bind('click', bb); // 恢复click事件
		return prompt("请输入11位正确的手机号码");
	}else if(vfycode == ""){
		return prompt("请输入短信验证码");
	}
	
	
	$.ajax({
		type : 'POST',
		url: baseUrl+"/credit_card_handle/apply_submit",
		data : {
		   _method : 'POST',
		   _token : csrf_token,
		   param : param,
		   true_name : own_name,
		   id_card : own_identity,
		   mobile : own_phone,
		   verification_code : vfycode
		},
		dataType : 'json',
		success : function(data) {
			if (data.code == 11001) {
				// 清空表单
				$("#user_name").val("");
				$("#user_identity").val("");
				$("#user_phone").val("");
				window.location.href = data.data.return_handle_url;
			} else {
				return prompt(data.message);
			}
		},
		error : function(data) {
		}
	});
});

//提交后获取信息，并相应赋值
function getValue(){
	var user_name = document.getElementById("user_name").value;
	var user_identity = document.getElementById("user_identity").value;
	var user_phone = document.getElementById("tel").value;

	document.getElementsByClassName("submit_name")[0].innerHTML = user_name;
	document.getElementsByClassName("submit_identity")[0].innerHTML = user_identity;
	document.getElementsByClassName("submit_phone")[0].innerHTML = user_phone;
}

